<template>
<div>
  <div>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="name"
        label="姓名"
        width="200">
      </el-table-column>
      <el-table-column
        prop="academic"
        label="学院">
      </el-table-column>
      <el-table-column
        prop="health"
        label="健康状态">
      </el-table-column>
      <el-table-column
        prop="statue"
        label="工作状态">
      </el-table-column>
      <el-table-column
        prop="operation"
        label="操作"
        align="center"
        width="300px"
      >
        <template slot-scope="scope">
          <el-button
            type="primary"

          >编辑</el-button
          >
          <el-button
            type="primary"
            @click="dialogFormVisible = true,
                editInFo(scope.row)
                    "
          >修改密码</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>

  <div>
    <el-dialog title="修改用户名和密码" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="form.name" ></el-input>
        </el-form-item>
      </el-form>
      <el-form :model="form">
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="form.password" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false,submitPass()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</div>

</template>

<script>
import axios from 'axios'

export default {
  data () {
    return {
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name:'',
        password:'',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      formLabelWidth: '120px',
      dialogFormVisible: false,
      tableData: []

    }
  },
  created () {
      this.getParams();
  },
  mounted () {

  },
  methods:{
    editInFo(row) {
      // 这里row是dataTable数组
      let that = this;
      this.form.name=row.name;
      this.form.passwrod=row.password;
      //console.log(row);
      that.editForm = {};
      that.editForm = row;
    },
    getParams(){
      const routerParams = this.$route.query.table;
      this.tableData=routerParams
    },
    submitPass(){
      let postData = this.$qs.stringify({
        username:this.form.name,
        password: this.form.password,
      })
      axios.post(`http://localhost:8181/user/editPass`,postData)
      .then(res=>{
        console.log(res)
      })
    }
  },
  watch: {
// 监测路由变化,只要变化了就调用获取路由参数方法将数据存储本组件即可
    '$route': 'getParams'
  }
}
</script>
